package com.dom.domweb.dao.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dom.common.constants.ConstantError;
import com.dom.common.enums.PubStatEnum;
import com.dom.common.exception.ServiceException;
import com.dom.common.model.vo.basic.*;
import com.dom.common.utils.BeanUtil;
import com.dom.domweb.dao.entity.TMenuInfo;
import com.dom.domweb.dao.mapper.TMenuInfoMapper;
import com.dom.domweb.dao.service.ITMenuInfoService;
import com.xiaoleilu.hutool.util.ObjectUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * B_菜单信息表 服务实现类
 * </p>
 *
 * @author xllei
 * @since 2018-11-17
 */
@Service
public class TMenuInfoServiceImpl extends ServiceImpl<TMenuInfoMapper, TMenuInfo> implements ITMenuInfoService {
    @Override
    public List<TMenuInfo> getMenuList(Integer memCode, List<Integer> roles) {
        return this.baseMapper.findMenuList(memCode, roles);
    }

    @Override
    public List<TMenuInfo> getRoleMenuList(Integer memCode, List<Integer> roles) {
        return this.baseMapper.findRoleMenuList(memCode, roles);
    }

    @Override
    public B212A updateMenuInfo(B212R request) {
        TMenuInfo menuInfo = this.selectById(request.getMenuId());
        if(ObjectUtil.isNull(menuInfo)){
            throw new ServiceException(ConstantError.ILLQUERYERROR);
        }

        BeanUtil.copyPropertiesIgnoreNull(request, menuInfo);
        menuInfo.setFatherMenuId(request.getFatherMenuId());

        this.updateById(menuInfo);

        B212A response = new B212A();
        response.setMenuId(menuInfo.getMenuId());
        return response;
    }

    @Override
    public B210A addMenuInfo(B210R request) {
        TMenuInfo menuInfo = new TMenuInfo();
        BeanUtil.copyPropertiesIgnoreNull(request, menuInfo);
        boolean result = this.insert(menuInfo);
        B210A response = new B210A();
        response.setMenuId(menuInfo.getId());
        return response;
    }

    @Override
    public B211A delMenuInfo(B211R request) {
        TMenuInfo menuInfo = this.selectById(request.getMenuId());
        if (ObjectUtil.isNull(menuInfo)) {
            throw new ServiceException(ConstantError.ILLQUERYERROR);
        }
        menuInfo.setStat(PubStatEnum.STAT_STOP.getCode());
        this.updateById(menuInfo);
        B211A response = new B211A();
        response.setMenuId(menuInfo.getId());
        return response;
    }
}
